<?php
class WDealTwitter extends UWidgetWorklet
{
	public $show = true;
	public $space = 'sidebar';
	
	public function accessRules()
	{
		return array(array('allow','users'=>array('*')));
	}
	
	public function taskConfig()
	{
		if(!$this->param('twitter'))
			return $this->show = false;
		parent::taskConfig();
	}
	
	public function taskRenderOutput()
	{
		$this->render('head');
		
		$id = $this->getDOMId().'-'.$this->param('twitter');
		echo CHtml::tag('div',array('id' => $id),'');
		
		$options = array(
			'account' => $this->param('twitter'),
		);	
		
		if($this->show)
			cs()->registerScript(__CLASS__.'#'.$id, '$("#'.$id.'").uDealTwitter('.CJavaScript::jsonEncode($options).');');
	}
}